﻿
using System;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Builder;
using ExaminationSystem.EntityFrameworkCore;

namespace ExaminationSystem.Web
{
    [DependsOn(
        typeof(AbpAspNetCoreMvcModule),
        typeof(ExaminationSystemEntityFrameworkCoreModule)
    )]
    public class ExaminationSystemWebModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services = context.Services;
            services.AddCors(s => s.AddPolicy("Any", p => p.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
                {
                    Title = "ExaminationSystem.Web",
                    Version = "1.0",
                    Contact = new Microsoft.OpenApi.Models.OpenApiContact()
                    {
                        Url = new Uri("http://www.cssoft.com"),
                        Email = "172399463@qq.com",
                        Name = "Dovey"
                    },
                    Description = "项目实战",
                    TermsOfService = new Uri("http://www.baidu.com")
                });
            });
        }
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var env = context.GetEnvironment();
            var app = context.GetApplicationBuilder();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(s =>
                {
                    s.SwaggerEndpoint("/swagger/v1/swagger.json", "ExaminationSystem.Web V1");
                });
            }
            app.UseRouting();

            app.UseCors("Any");
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
